<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>器械还回</title>
<link rel="stylesheet" type="text/css"
	href="<c:url value="/css/themes/default/easyui.css"/>">
<link rel="stylesheet" type="text/css"
	href="<c:url value="/css/themes/icon.css"/>">
<script type="text/javascript" src="<c:url value="/js/jquery.min.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/js/jquery.easyui.min.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/js/easyui-lang-zh_CN.js"/>"></script>
</head>

<body>
<script type="text/javascript">
$(function(){
	//还回器械获取数据
	$('#thphhckdx').combogrid({
		onChange: function (newValue, oldValue) {
			//alert(typeof(newValue)+":"+newValue);
			$("#thphhqx").combogrid({
	    		url: 'getHisDetailsofequipmentANDHisDepartmentAllInfo', 
	    		method: 'post', 
	    		queryParams: {
	    			qxlyxqObject: newValue
	    		},
	    		idField:'qclyxqNo',
	    		panelWidth:'206',
				panelHeight:'auto',
				textField:'qcName',
				columns:[[{field:'qcName',title:'器械名称',width:'100px'},
				          {field:'qclyxqDate',title:'领用日期',width:'100px'}]]
			});
			$('#qxReturnInfo').form('clear');
		}
	});
	
	//判断器械数据
	$('#thphhqx').combogrid({
		onShowPanel :function(){
			var object=$('#thphhckdx').combogrid('getValue');
			if(object==''){
				$.messager.alert("温馨提示", "请先选择还回对象!",'info');
			}
		}
	});
	
	//赋值
	$('#thphhqx').combogrid({
		onChange: function (newValue, oldValue) {
			var qcName=$('#thphhqx').combogrid('getText');
			$.getJSON("selectHisDetailsofequipmentByLyId", {"qclyxqNo": newValue}, function(data){
				$('#qxlysl').numberbox('setValue',data.qclyxqNumber);
				$('#qxhhsl').numberspinner({max:data.qclyxqNumber});
			});
			$.getJSON("selectHisPurchaseByName", {"cpName": qcName}, function(data){
				$('#qxph').textbox('setValue',data.cgBatchnumber);
			});
		}
	});
	
	//数字微调
	$('#qxhhsl').numberspinner({
		onChange: function (newValue, oldValue) {
			var qxlysl=$('#qxlysl').numberbox('getValue');
			if(qxlysl==''){
				$.messager.alert('温馨提示', '请先选择您需要还回的产品名称!','info');
				$('#qxhhsl').numberspinner('setValue',0);
				$('#qxlysl').numberbox('setValue','');
			}else{
				var jcsl=$('#qxlysl').numberbox('getValue');
				var o=parseInt(jcsl)+parseInt(oldValue)-parseInt(newValue);
				$('#qxlysl').numberbox('setValue',o);
			}
		}
	});
	
	//加入临时还回表
	$('#add-ReturnTable').linkbutton({
		onClick : function() {
			var qxhhDate=$('#qxhhDate').datebox('getText');
			var qxhhck=$('#qxhhck').combogrid('getText');
			var thphhckdx=$('#thphhckdx').combogrid('getText');
			var thplyqxID=$('#thphhqx').combogrid('getValue');			
			var thphhqxName=$('#thphhqx').combogrid('getText');
			var qxph=$('#qxph').textbox('getText');
			var qxlysl=$('#qxlysl').numberbox('getText');
			var qxhhsl=$('#qxhhsl').numberspinner('getText');
			var qxhhbz=$('#qxhhbz').textbox('getText');
			$.getJSON("selectHisPurchaseByName", {"cpName": thphhqxName}, function(data){
				var unit=data.cgUnit;
				var id=data.cgNo
				
				var rows=$('#thpqxReturn').datagrid('getRows');
				var ii=0;
				for(var i=0;i<rows.length;i++){
					var name=rows[i].cpName;
					if(name==thphhqxName){
						ii++;
					}
				}
				if(thphhckdx=='' || qxhhDate=='' || qxhhck=='' || thphhqxName=='' || parseInt(qxhhsl)<1 ){
					$.messager.alert("温馨提示", "请把数据填充完整!",'info');
				}else if(ii>0){
					$.messager.alert("提示", "产品已存在临时还回中，请勿重复添加!");
					$('#qxReturnInfo').form("clear");
				}else{
					$('#thpqxReturn').datagrid('appendRow', {
						'hisDetailsofreturns.qclyxqNo' : thplyqxID,
						'hisDetailsofreturns.cpNo' : id,
						'cpName' : thphhqxName,
						'hisDetailsofreturns.ckBalance' : qxlysl,
						'cgUnit' : unit,
						'cgBatchnumber' : qxph,
						'hisDetailsofreturns.qchhxqNumber' : qxhhsl,
						'hisDetailsofreturns.qchhxqRemarks' : qxhhbz
					});
					$('#qxReturnInfo').form("clear");
				}
			});
		}
	});
	
	//还回
	$('#submit-qxReturn').linkbutton({
		onClick : function() {
			//将datagrid中的数据行保存到隐式表单域中
			//1、获取新增的数据行
			var rows = $('#thpqxReturn').datagrid('getChanges');
			//为每一行生成对应的隐藏表单域
			var today='${DetailsofreturnId }'*1;
			var ff_DetailsofReturn=$('#ff_DetailsofReturn');
			var qxhhDate=$('#qxhhDate').datebox('getText');
			var qxhhck=$('#qxhhck').combogrid('getValue');
			var thphhckdx=$('#thphhckdx').combogrid('getValue');
			var qxhhState='已还回';
			for(var i = 0; i < rows.length; i ++){
				$("<input type='hidden' x='y'>").attr("name",
						"hisDetailsofreturns[" + i + '].qchhxqNo').val(
								today+i).appendTo(ff_DetailsofReturn);
				$("<input type='hidden' x='y'>").attr("name",
						"hisDetailsofreturns[" + i + '].ckNo').val(
								qxhhck).appendTo(ff_DetailsofReturn);
				$("<input type='hidden' x='y'>").attr("name",
						"hisDetailsofreturns[" + i + '].qchhxqDate').val(
								qxhhDate).appendTo(ff_DetailsofReturn);
				$("<input type='hidden' x='y'>").attr("name",
						"hisDetailsofreturns[" + i + '].qchhxqObject').val(
								thphhckdx).appendTo(ff_DetailsofReturn);
				$("<input type='hidden' x='y'>").attr("name",
						"hisDetailsofreturns[" + i + '].qchhxqState').val(
								qxhhState).appendTo(ff_DetailsofReturn);
				generateHidden(rows[i], "qclyxqNo", i);
				generateHidden(rows[i], "cpNo", i);
				generateHidden(rows[i], "ckBalance", i);
				generateHidden(rows[i], "qchhxqNumber", i);
				generateHidden(rows[i], "qchhxqRemarks", i);
			}
			//提交表单
			if(rows.length != 0){
				$('#ff_DetailsofReturn').form('submit', {
					success: function(v){
						var json = eval("(" + v + ")");
						//alert(json);
						if(json=='操作成功'){
							$(":hidden[x='y']").remove();
							$('#thpqxReturn').datagrid('loadData', { total: 0, rows: [] });
							$.messager.alert('温馨提示', "还回"+json);
							$('#ff_DetailsofReturn').form("clear");
							$("#win-QiXieReturn").window("close");
						}else{
							$.messager.alert('温馨提示', json,'info');
						}
					}
				});
			}
		}
	});
	
	function generateHidden(row, name, i) {
		var ff_DetailsofReturn = $("#ff_DetailsofReturn");
		$("<input type='hidden' x='y'>").attr("name",
				"hisDetailsofreturns[" + i + '].'  + name).val(
				row['hisDetailsofreturns.'+name]).appendTo(ff_DetailsofReturn);
	}
});
</script>
<style type="text/css">
	*{
		font-size:12px;
	}
	#QiXieReturnContent{
		padding-bottom: 10px;
	}
	#QiXieReturnInfo{
		width:100%;
		overflow: hidden;
	}
	li{
		float: left;
		list-style: none;
	}
</style>

	<!-- 器械还回 -->
	<!-- <div id="win-QiXieReturn" class="easyui-window" title="器械还回" data-options="collapsible:false,
		minimizable:false,
		maximizable:false,
		modal:true,
		iconCls:'icon-return'"
		style="width: 806px; height: 500px;"> -->
		<form id="ff_DetailsofReturn" action="addQiXieDetailsofreturn" method="post">
			<div id="QiXieReturnContent">
				<div id="QiXieReturnInfo" style="background-color: rgb(236,243,255)">
					<ul>
						<li style="margin:0px 30px 5px 0px;">还回单编号&nbsp;<input value="${DetailsofreturnId }" class="easyui-textbox" data-options="width: 150" readonly="readonly"></li>
						<li style="margin:0px 0px 5px 0px;">状态&nbsp;<select class="easyui-combobox" data-options="width: 80" readonly="readonly">
							<option value="未还回" selected="selected">未还回</option><option value="已还回">已还回</option></select></li>
						<li style="margin:0px 30px 5px 30px;">仓库&nbsp;<input id="qxhhck" class="easyui-combogrid" data-options="width: 100,
							url:'selectAllHisWarehouse',
							idField:'ckNo',
							panelHeight:'auto',
							textField:'ckName',
							columns:[[
					            {field:'ckName',title:'仓库名称',width:'96px'}
							]]"></li>
						<li style="margin:0px 0px 5px 0px;">还回日期&nbsp;<select id="qxhhDate" class="easyui-datebox" data-options="width: 150"></select></li>
						<li style="margin:0px 0px 10px 12px;">还回对象&nbsp;<input id="thphhckdx" class="easyui-combogrid" data-options="width: 150,
							url:'selectAllHisDepartment',
							idField:'ksNo',
							panelHeight:'auto',
							textField:'ksName',
							columns:[[
					            {field:'ksName',title:'科室名称',width:146}
							]]"></li>
					</ul>
				</div>
				<div style="border-top:1px solid #95B8e7;width:100%;height:346px;overflow: hidden;">
			        <div>
			        	<div id="qxReturnInfo" style="overflow: hidden;" >
			        		<ul>
								<li style="margin:5px 35px 0px 0px;">器械&nbsp;<select id="thphhqx" class="easyui-combogrid" data-options="width: 184"></select></li>
								<li style="margin:5px 42px 0px 0px;">批号&nbsp;<input id="qxph" class="easyui-textbox" data-options="width: 100" readonly="readonly"></li>
								<li style="margin:5px 34px 0px 0px;">待还数量&nbsp;<input id="qxlysl" class="easyui-numberbox" data-options="width: 100" readonly="readonly"></li>
								<li style="margin:5px 0px 0px 0px;">还回数量&nbsp;<input id="qxhhsl" class="easyui-numberspinner" value="0" data-options="width: 80,min:0,editable:true"></li>
								<li style="margin:10px 0px 10px 0px;">备注&nbsp;<input id="qxhhbz" class="easyui-textbox" data-options="width: 540"></li>
								<li style="margin:10px 2px 10px 85px;"><a id="add-ReturnTable" class="easyui-linkbutton" style="width:80px;">加入</a></li>
							</ul>
			        	</div>
			        	<div style="border:0px red solid;height:256px;">
							<table id="thpqxReturn" class="easyui-datagrid"
								data-options="
									fitColumns:true,
									fit:true,
									singleSelect: true,
									rownumbers: true,
									pagination: true,
									pageSize: 5,
									toolbar: '#qxReturntb',
									pageList: [5,10,15,20],
									border:false
									">
								<thead>
									<tr>
										<th data-options="field:'hisDetailsofreturns.qclyxqNo',width:'13%'">领用编号</th>
										<th data-options="field:'hisDetailsofreturns.cpNo',width:'13%'">器械编号</th>
										<th data-options="field:'cpName',width:'15%'">器械名称</th>
										<th data-options="field:'hisDetailsofreturns.ckBalance',width:'10%'">待还数量</th>
										<th data-options="field:'cgUnit',width:'8%'">单位</th>
										<th data-options="field:'cgBatchnumber',width:'11%'">批号</th>
										<th data-options="field:'hisDetailsofreturns.qchhxqNumber',width:'10%'">还回数量</th>
										<th data-options="field:'hisDetailsofreturns.qchhxqRemarks',width:'20%'">备注</th>
									</tr>
								</thead>
							</table>
							<div id="qxReturntb" style="height: auto;padding-left: 30px;">
								<a href="javascript:void(0)" class="easyui-linkbutton"
								data-options="iconCls:'icon-add',plain:true">添加一行</a>
								<a href="javascript:void(0)" class="easyui-linkbutton"
									data-options="iconCls:'icon-remove',plain:true"
									onclick="removeit()">移除一行</a> <a href="javascript:void(0)"
									class="easyui-linkbutton"
									data-options="iconCls:'icon-ok',plain:true">应用</a>
								<a href="javascript:void(0)" class="easyui-linkbutton"
									data-options="iconCls:'icon-undo',plain:true" onclick="reject()">撤销</a>
							</div>
			        	</div>
			        </div>
			    </div>
			    <div style="margin:5px 5px 0px 0px;text-align: right;">
					<a id="submit-qxReturn" class="easyui-linkbutton" data-options="iconCls:'icon-ok'">还回</a>
					<a class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" href="javascript:$('#win-QiXieReturn').window('close');" onclick="">取消</a>
				</div>
			</div>
		</form>
	<!-- </div> -->
</body>
</html>